<template>
	<view>
		<!-- 余额 height: calc(100vh - 88rpx);-->
		<view class=" flex-col " style="height:100vh;">
			<view class="">
				<view class="bgWhite ">
					<view class="align-center justify-between plr14 bdbe ptb15">
						<view>
							<view class="gray9 ft14 pb5">
								<text>{{$t('mine').账户余额}}（{{$store.state.currency=='CNY'?$t('index').元:$t('index').美元}}）</text>
							</view>
							<view class="ft24 gray3 bold">
								<text>{{userInfo.view_total_money }}</text>
							</view>
						</view>
						<view class="bdF42 light radius22 ptb5 plr10 ft14"
							@click="navTo('/pages/wallet/flowingDetails')">
							<text>{{$t('mine').流水明细}}</text>
						</view>
					</view>
					<view class="justify-between plr14 ptb15">
						<view style="flex-basis: 40%;">
							<view class="ft12 gray9 pb5">
								<text>{{$t('mine').可提现}}({{$store.state.currency=='CNY'?$t('index').元:$t('index').美元}})</text>
							</view>
							<view class="align-center">
								<view class="ft16 gray3 bold">
									<text>{{userInfo.view_money}}</text>
								</view>
								<view class="align-center ml5" @click="isdianqian()">
									<view class="ft12 light " style="margin-right: 6rpx;"><text>{{$t('mine').提现}}</text>
									</view>
									<image src="../../static/images/wallet/hongjiantou.png" mode="aspectFill"
										style="width: 9rpx;height: 17rpx;"></image>
								</view>
							</view>
						</view>
						<view style="flex-basis: 35%;">
							<view class="ft12 gray9 pb5 align-center mr5">
								<text>{{$t('mine').待结算}}({{$store.state.currency=='CNY'?$t('index').元:$t('index').美元}})</text>
								<!-- <u-icon name="info-circle" color="#999999" @click="showd=true"></u-icon> -->
							</view>
							<view class="ft16 gray3 bold">
								<text>{{statistics.not_amt_award |changeCurrency}}</text>
							</view>
						</view>
						<view style="flex-basis: 25%;">
							<view class="ft12 gray9 pb5">
								<text>{{$t('mine').待入账元}}({{$store.state.currency=='CNY'?$t('index').元:$t('index').美元}})</text>
							</view>
							<view class="ft16 gray3 bold">
								<text>{{statistics.total_amt_award |changeCurrency}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="align-center plr14 ptb15 " @click="navTo('/pages/wallet/entryIllustrate')">
					<view class="mr5 gray3 ft16 bold"><text>{{$t('mine').待入账}}</text></view>
					<image src="../../static/images/fans/icon_wenhao.png" mode="aspectFill"
						style="width: 28rpx;height: 28rpx;"></image>
				</view>
			</view>
			<!-- 账单 -->
			<view class="flex1 overhide" style="min-height: 0;">
				<mescroll-uni top='0' :fixed="false" @init="mescrollInit" @down="downCallback" @up="upCallback"
					:up="upOption" :down="downOption">
					<!-- <view v-if="orderLists.length>0"> -->
					<view class="bgWhite mb10" v-for="(item,index) in orderLists" :key="index">
						<view class="align-center justify-between plr14 ptb15" v-if="item.awardorder">
							<view><text>{{$t('fandetail').订单号}}：{{item.order_sn}}</text></view>
							<!-- 						<text v-if="item.awardorder.status==1" style="color: #F44A42;">{{$t('common').待发货}}</text>
						<text v-if="item.awardorder.status==3" style="color: #F44A42;">{{$t('common').待收货}}</text>
						<text v-if="item.awardorder.status==2">{{$t('common').已完成}}</text>
						<text v-if="item.awardorder.status==4">{{$t('common').已收货}}</text>
						<text v-if="item.awardorder.status==-1" class="gray9">{{$t('common').已取消}}</text>
						 -->
							<text v-if="item.awardorder.order_status==1"
								style="color: #F44A42;">{{$t('common').待发货}}</text>
							<text v-if="item.awardorder.order_status==2"
								style="color: #F44A42;">{{$t('common').待收货}}</text>
							<text v-if="item.awardorder.order_status==3">{{$t('common').已完成}}</text>
							<text v-if="item.awardorder.order_status==4">{{$t('common').已关闭}}</text>
							<text v-if="item.awardorder.order_status==-1" class="gray9">{{$t('common').已取消}}</text>
							<!-- <text>{{$t('mine').待入账}}</text> -->
						</view>
						<view class="plr14 align-start" v-if="item.good">
							<image class="radius5" :src="item.good.image" mode="aspectFill"
								style="width: 168rpx;height: 168rpx;">
							</image>
							<view class="flex1 pl12">
								<view style="height: 74rpx;" class="clamp2">
									<!-- {{item.good.sku_name}} -->
									<text>{{item.good.store_name}}</text>
								</view>
								<view class="align-center justify-between pt15">
									<view class="ft12 gray9 ">
										<text>{{$t('mine').共}}{{item.good.product_num}}{{$t('mine').件}}</text>
									</view>
									<view class="ft13" style="color: #F23C4B;">
										<text>{{$t('fandetail').赚}}{{curreny=='USD'?'$':'￥'}}{{parseFloat(item.total_amt_award) |changeCurrency}}</text>
									</view>
								</view>
							</view>
						</view>
						<view class=" plr14  ">
							<view class="ft14 gray3 bold tr pb15 bdbe">
								<!--  total_amt_consumed-->
								<text>{{$t('fan').合计}}：{{item.country==1?'￥':'$'}}<text
										v-if="item.awardorder">{{parseFloat(item.awardorder.total_price)}}</text><text
										v-else>0</text></text>
							</view>
						</view>
						<view class="align-center ptb10 plr14">
							<view class="ft14"><text>{{$t('fandetail').下单人}}：</text></view>
							<view class="align-center" v-if="item.user">
								<image class="radius50" :src="item.user.avatar" mode="aspectFill"
									style="width: 64rpx;height: 64rpx;">
								</image>
								<view class="ft14 ml10"><text>{{item.user.nickname}}</text></view>
							</view>
						</view>
					</view>
					<!-- </view> -->
					<!-- 					<view class="mt10 tc" v-else>
						<image src="../../static/images/empty/none.png" mode="" style="width: 520upx;height: 380upx;">
						</image>
						<view class="ft15">{{$t('common').暂无数据}}</view>
					</view> -->
				</mescroll-uni>
			</view>
		</view>
		<!-- 待结算 -->
		<!-- 中间弹窗 -->
		<u-popup :show="showd" @close="close" mode="center" round="8px" :safeAreaInsetBottom="false">
			<view class="tc bdbe justify-center align-center" style="width: 600rpx;height: 150rpx;">
				<view class="ft14 " style="width: 600rpx;"><text>{{$t('mine').每个月自动结算上个月入账的订单收益}}</text></view>
			</view>
			<view class="tc" style="width: 600rpx;height: 80rpx;line-height: 80rpx;" @click="know()">
				<view class="ft15 light"><text>{{$t('fan').我知道了}}</text></view>
			</view>
		</u-popup>
		<!-- 切换币种弹窗 -->
		<u-overlay :show="is_show1" @click="is_show1 = false" opacity=".4">
			<view class="t-box">
				<view class="txt3" style="" @tap.stop>
					<view class="title1">{{$t('mine').提现币种要求}}</view>
					<view class="bot-btn1">
						<view class="btn-l" @click="refu()">{{$t('mine').暂不提现}}</view>
						<view class="line1"></view>
						<view class="btn-r" @click="agree()">{{$t('mine').切换币种}}</view>
					</view>

				</view>
			</view>
		</u-overlay>

	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				is_show1: false, //切换币种
				orderLists: [],
				statistics: {},
				curreny: uni.getStorageSync('currency'), //币种
				showd: false,
				accountBalance: 0,
				downOption: {
					auto: true
				},
				upOption: {
					auto: false,
					page: {
						num: 0,
						size: 20,
					},
					textNoMore: this.$t('common').已经到底了,
					empty: {
						tip: this.$t('common').暂无数据 // 空提示
					}
				},

			}
		},
		onLoad() {
			// this.walletorderlistAPI()
			uni.setNavigationBarTitle({
				title: this.$t('mine').我的钱包
			})
			this.$store.dispatch('getuserInfo')
		},
		onShow() {
			this.$store.dispatch('getuserInfo')
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			}
		},
		methods: {

			refu() {
				this.is_show1 = false
			},
			agree() {
				uni.setStorageSync('currency', 'CNY')
				this.$store.commit("saveCurrency", 'CNY')
				this.$store.dispatch('getuserInfo')
				this.is_show1 = false
			},
			// 钱包信息
			// async walletorderlistAPI() {
			// 	const res = await this.$api.walletorderlist()
			// 	this.statistics = res.data.statistics
			// 	this.orderLists = res.data.list
			// },
			// 下拉刷新  现货列表
			upCallback(page) {
				if (page.num == 1) this.orderLists = []; //如果是第一页需手动制空列表
				this.$api.walletorderlist({
					page: page.num,
					limit: page.size
				}).then(res => {
					let curPageData = res.data.list; //当前页的数据列表
					let curPageLen = curPageData?.length; //当前页的数据长度
					let totalPage =  Math.ceil(res.data.count/20); //总页数
					console.log(totalPage)
					let hasNext = page.num === totalPage ? false : true //根据页数判断是否有下一页
					this.orderLists = this.orderLists.concat(curPageData); //追加新数据
					this.mescroll.endSuccess(curPageLen, hasNext);
					this.statistics = res.data.statistics
				})
			},
			know() {
				this.showd = false
			},
			close() {
				this.showd = false
			},
			async isdianqian() {
				if (uni.getStorageSync('currency') != 'CNY') {
					return this.is_show1 = true
				}
				if (this.userInfo.area == 1) {
					//国内
					if (this.userInfo.sign_status == 1) {
						this.navTo(`/pages/wallet/bindCard`) //电签（国内、港澳）、国内换绑银行卡
						// this.navTo('/pages/wallet/perfect-rebinding')//港澳完善、换绑
						// this.navTo('/pages/wallet/progress')//港澳电签进度
						// this.navTo('/pages/wallet/agency')//港澳在线签约
						// this.navTo(`/pages/wallet/withdraw`)//提现 

					} else {
						this.navTo(`/pages/wallet/withdraw`) //提现 
					}
				} else {
					// 获取回显的银行卡信息
					const res = await this.$api.getbank()
					if (res && res.code == 1) {
						if (res.data && res.data.username) {
							if (res.data.step && res.data.step == 3) {
								this.navTo(`/pages/wallet/withdraw?val=1`) //提现 
							} else if (res.data&& res.data.step >= -1) {
								this.navTo('/pages/wallet/progress?val=' + res.data.step)
							}else{
								this.navTo(`/pages/wallet/bindCard?val=1`)
							}

						} else {
							this.navTo(`/pages/wallet/bindCard?val=1`)
						}
					}
					//港澳台提现
					//判断当前币种
					// this.is_show1=true
					this.navTo(`/pages/wallet/bindCard?val=1`) //电签（国内、港澳）、国内换绑银行卡
					// if (this.userInfo.sign_status == 1) {
					// 	this.navTo(`/pages/wallet/withdraw?val=1`)//提现 
					// } else {
					// 	this.navTo(`/pages/wallet/bindCard?val=1`)//电签（国内、港澳）、国内换绑银行卡
					// }

				}
			}

		}
	}
</script>

<style lang="scss">
	.t-box {
		height: 100vh;
		width: 100vw;
		display: flex;
		justify-content: center;
		align-items: center;

		.txt3 {
			width: 640upx;
			padding-top: 54upx;
			background: #FFFFFF;
			margin-top: -260upx;
			border-radius: 10upx;

			.title1 {
				width: 530upx;
				margin: 0 auto;
				// margin-top: 54upx;
				font-size: 32upx;
			}

			.bot-btn1 {
				border-top: 1upx solid #EEEEEE;
				margin-top: 46upx;
				width: 640upx;
				height: 96upx;
				display: flex;
				justify-content: space-between;
				text-align: center;
				align-items: center;
				font-size: 30upx;

				.btn-l {
					width: 319upx;
					color: #333333;
				}

				.line1 {
					width: 2upx;
					height: 94upx;
					background-color: #EEEEEE;
				}

				.btn-r {
					width: 319upx;
					color: #F44A42;
				}
			}

		}

	}
</style>